package com.game.data.vo
{
    import com.dusk.util.RandomUtil;
    import com.dusk.util.StringUtil;
    import com.game.data.constant.MaxAttribConst;
    import com.game.data.vo.attribute.BaseAttribVO;
    import com.game.manager.NotificationManager;
    
    public class PetDataVO extends BaseAttribVO
	{
		
		public function PetDataVO()
		{
			this.allSkill = ["tsml", "zrsh", "smzf", "mfby", "qlfj", "sxkb", "fsnl", "smjc", "mfjc", "gjjc", "fyjc"];
			super();
		}
		
		//移动速度
		public var moveSpeed:int = 5;
		
		//血量资质
		public var hpQuality:int = 0;
		//魔力资质
		public var mpQuality:int = 0;
		//攻击资质
		public var atkQuality:int = 0;
		//防御资质
		public var defQuality:int = 0;
		
		//悟性
		public var perception:int = 0;
		//灵力
		public var technique:int = 0;
		//根骨
		public var warpower:int = 0;
		//品质
		public var quality:int = 0;
		
		//是否在战斗中
		public var isFight:uint = 0;
		//等级
		public var level:uint = 0;
		//当前经验
		public var curExp:uint = 0;
		//宠物名字
		public var petName:String;
		//已学习技能
		public var skill:Array = [];
		//中文名字
		public var petChinaName:String = "";
		//所有技能
		public var allSkill:Array;
		//寿命
		private var _lifetime:int = 0;
		private var doWhenLevelUp:Function = null;
		private var doWhenChangeState:Function = null;
		
		public function clone():PetDataVO
		{
			var vo:PetDataVO = new PetDataVO();
			vo.buildFromObject(cloneToObject());
			return vo;
		}
		
		private function get petId():String
		{
			return StringUtil.trimLastMultiChars(petName, 1);
		}
		
		private function get petState():int
		{
			return int(StringUtil.getLastMultiChars(petName, 1));
		}
		
		public function setPetNameAndLevel(petName:String, petLevel:uint = 1):void
		{
			this.petName = petName;
			level = petLevel;
			curExp = 0;
			lifetime = 100;
			quality = petLevel == 1 ? 1 : 2;
			transPetChinaName();
			addSpecialSkill();
			upPassive();
			initPetInfoData();
		}
		
		public function upPassive():void
		{
			var a:int = level / 5;
			hpHeal = mpHeal = a;
		}
		
		public function resetPetState():void
		{
			setFullHp();
			setFullMp();
		}
		
		public function addExp(value:int = 0):void
		{
			curExp += value;
			petUpdate();
		}
		
		/**
		 * 克隆为对象
		 * @return 克隆后的对象
		 */
		override public function cloneToObject():Object
		{
			var obj:Object = {};
			obj.petName = this.petName;
			obj.quality = this.quality;
			obj.isFight = this.isFight;
			obj.level = this.level;
			obj.curExp = this.curExp;
			obj.lifetime = this.lifetime;
			
			obj.hp = this.hp;
			obj.hpMax = this.hpMax;
			obj.hpHeal = this.hpHeal;
			obj.mp = this.mp;
			obj.mpMax = this.mpMax;
			obj.mpHeal = this.mpHeal;
			obj.level = this.level;
			obj.curExp = this.curExp;
			obj.atk = this.atk;
			obj.def = this.def;
			obj.crit = this.crit;
			obj.toughness = this.toughness;
			obj.miss = this.miss;
			obj.hit = this.hit;
			obj.magicDef = this.magicDef;
			obj.deMagicDef = this.deMagicDef;
			obj.moveSpeed = this.moveSpeed;
			
			obj.hpQuality = this.hpQuality;
			obj.mpQuality = this.mpQuality;
			obj.atkQuality = this.atkQuality;
			obj.defQuality = this.defQuality;
			obj.perception = this.perception;
			obj.technique = this.technique;
			obj.warpower = this.warpower;
			var sklArr:Array = [];
			for each(var item:Object in this.skill)
			{
				sklArr.push(item.sname);
			}
			obj.skill = sklArr;
			return obj;
		}
		
		public function get lifetime():int
		{
			return _lifetime;
		}
		
		public function refreshPetAllSkillByLevel():void
		{
			this.deletePassiveWhenUpdata();
			this.allSkill = ["tsml", "zrsh", "smzf", "mfby", "qlfj", "sxkb", "fsnl", "smjc", "mfjc", "gjjc", "fyjc"];
			this.skill = [];
			this.rePetSkill();
		}
		
		/**
		 * 从对象更新数据
		 * @param data 数据
		 */
		override public function updateFromObject(data:Object):void
		{
			this.petName = data.petName;
			this.quality = data.quality;
			this.isFight = data.isFight;
			this.level = data.level;
			this.curExp = data.curExp;
			this.lifetime = data.lifetime;
			
			this.hp = data.hp;
			this.hpMax = data.hpMax;
			this.hpHeal = data.hpHeal;
			this.mp = data.mp;
			this.mpMax = data.mpMax;
			this.mpHeal = data.mpHeal;
			this.level = data.level;
			this.curExp = data.curExp;
			this.atk = data.atk;
			this.def = data.def;
			this.crit = data.crit;
			this.toughness = data.toughness;
			this.miss = data.miss;
			this.hit = data.hit;
			this.magicDef = data.magicDef;
			this.deMagicDef = data.deMagicDef;
			this.moveSpeed = data.moveSpeed;
			
			this.hpQuality = data.hpQuality;
			this.mpQuality = data.mpQuality;
			this.atkQuality = data.atkQuality;
			this.defQuality = data.defQuality;
			this.perception = data.perception;
			this.technique = data.technique;
			this.warpower = data.warpower;
			
			for each (var item:String in data.skill)
			{
				var sklObj:Object = {
					"sname": item,
					"sinfo": this.getIntroByName(item)
				};
				if (allSkill.indexOf(item) != -1)
				{
					allSkill.splice(allSkill.indexOf(item), 1);
				}
				this.skill.push(sklObj);
			}
			addSpecialSkill();
			transPetChinaName();
		}
		
		public function refreshThreeAttributeByImmortality():void
		{
			switch (quality)
			{
				case 1:
					perception = RandomUtil.randInt(3, 7);
					technique = RandomUtil.randInt(3, 8);
					warpower = RandomUtil.randInt(3, 8);
					break;
				default:
					perception = RandomUtil.randInt(1, 6);
					technique = RandomUtil.randInt(1, 6);
					warpower = RandomUtil.randInt(1, 6);
					break;
			}
		}
		
		public function petUpdate():void
		{
			if (level >= MaxAttribConst.MaxPetLevel)
			{
				return;
			}
			var needExp:int = getPetNextLevelExp();
			if (curExp >= needExp)
			{
				this.deletePassiveWhenUpdata();
				level += 1;
				if (level >= 16 && level < 30)
				{
					if (petState == 1)
					{
						this.petName = petId + (petState + 1);
						this.addSpecialSkill();
						if (this.doWhenChangeState != null)
						{
							this.doWhenChangeState();
						}
						this.transPetChinaName();
						this.changePetSkillIntroduce();
					}
				}
				else if (level > 30)
				{
					if (petState == 2)
					{
						this.petName = petId + (petState + 1);
						this.addSpecialSkill();
						if (this.doWhenChangeState != null)
						{
							this.doWhenChangeState();
						}
						this.transPetChinaName();
						this.changePetSkillIntroduce();
					}
				}
				this.studySkillSuddenly(level);
				this.addPassiveAfterUpdata();
				this.reSetPetAttributeValue();
				this.upPassive();
				if (this.doWhenLevelUp != null)
				{
					this.doWhenLevelUp();
				}
				curExp -= needExp;
			}
		}
		
		public function theFourShape():void
		{
			if (petState == 3)
			{
				this.deletePassiveWhenUpdata();
				this.petName = petId + (petState + 1);
				this.transPetChinaName();
				this.changePetSkillIntroduce();
				this.addPassiveAfterUpdata();
				this.studyEsoteric();
				if (this.doWhenChangeState != null)
				{
					this.doWhenChangeState();
				}
			}
		}
		
		/**
		 * 学习奥义
		 * @return 是否学习成功
		 */
		public function studyEsoteric():Boolean
		{
			var sklObj:Object = null;
			if (this.skill.length >= 8)
			{
				NotificationManager.alert("宠物技能已满，无法领悟奥义");
				return false;
			}
			switch (petId)
			{
				case "monkey":
					sklObj = {
						"sname": "jgaoyi",
						"sinfo": this.getIntroByName("jgaoyi")
					};
					break;
				case "horse":
					sklObj = {
						"sname": "tmaoyi",
						"sinfo": this.getIntroByName("tmaoyi")
					};
					break;
				case "dragon":
					sklObj = {
						"sname": "qlaoyi",
						"sinfo": this.getIntroByName("qlaoyi")
					};
					break;
				case "tigress":
					sklObj = {
						"sname": "bhaoyi",
						"sinfo": this.getIntroByName("bhaoyi")
					};
					break;
				case "phoenix":
					sklObj = {
						"sname": "zqaoyi",
						"sinfo": this.getIntroByName("zqaoyi")
					};
					break;
				case "turtle":
					sklObj = {
						"sname": "xwaoyi",
						"sinfo": this.getIntroByName("xwaoyi")
					};
					break;
				case "rabbit":
					sklObj = {
						"sname": "ysaoyi",
						"sinfo": this.getIntroByName("ysaoyi")
					};
					break;
				case "mouse":
					sklObj = {
						"sname": "zsaoyi",
						"sinfo": this.getIntroByName("zsaoyi")
					};
					break;
				case "roomhorse":
				default:
			}
			if (sklObj != null)
			{
				this.skill.push(sklObj);
				return true;
			}
			return false;
		}
		
		public function getIntroByName(skillName:String):String
		{
			var introduce:String = "";
			var harmData:Object = this.getPetHarmObj(skillName);
			switch (skillName)
			{
				case "tsml":
					introduce = "被动增加宠物攻击" + harmData.first + "点";
					break;
				case "zrsh":
					introduce = "被动增加宠物防御" + harmData.first + "点";
					break;
				case "smzf":
					introduce = "被动增加宠物生命" + harmData.first + "点";
					break;
				case "mfby":
					introduce = "被动增加宠物魔法" + harmData.first + "点";
					break;
				case "qlfj":
					introduce = "宠物被攻击时有" + int(Number(harmData.first) * 100) + "%的概率发动反击";
					break;
				case "sxkb":
					introduce = "提升宠物物理暴击率" + int(Number(harmData.first) * 100) + "%,持续" + harmData.second + "s";
					break;
				case "fsnl":
					introduce = "提升宠物技能伤害" + harmData.first + "点,持续" + harmData.second + "s";
					break;
				case "smjc":
					introduce = "提升主人" + harmData.first + "点生命,持续" + harmData.second + "s";
					break;
				case "mfjc":
					introduce = "提升主人" + harmData.first + "点魔法,持续" + harmData.second + "s";
					break;
				case "gjjc":
					introduce = "提升主人" + harmData.first + "点攻击,持续" + harmData.second + "s";
					break;
				case "fyjc":
					introduce = "提升主人" + harmData.first + "点防御,持续" + harmData.second + "s";
					break;
				case "xj":
					introduce = "附近有怪物时，自动燃烧，对怪物造成火焰伤害";
					break;
				case "lj":
					introduce = "对怪物造成多次伤害";
					break;
				case "lyq":
					introduce = "对前方怪物造成火焰伤害，附带灼烧效果";
					break;
				case "jgaoyi":
					introduce = "拥有献祭、连击、烈焰拳才能发挥出奥义的最大威力";
					break;
				case "sp":
					introduce = "吐出水泡攻击前方怪物";
					break;
				case "bd":
					introduce = "对攻击（靠近）它的怪物造成冰冻效果";
					break;
				case "bz":
					introduce = "对大范围的怪物造成伤害";
					break;
				case "tmaoyi":
					introduce = "拥有水泡、冰冻、冰锥才能发挥出奥义的最大威力";
					break;
				case "pms":
					introduce = "撕裂前方怪物";
					break;
				case "ss":
					introduce = "瞬间闪烁到怪物后面";
					break;
				case "kmsk":
					introduce = "飞到空中对下方怪物造成伤害";
					break;
				case "hy":
					introduce = "撕咬前方怪物";
					break;
				case "sxhz":
					introduce = "将怪物抓到空中，并吸取生命";
					break;
				case "hsqj":
					introduce = "对前方怪物造成伤害";
					break;
				case "bhaoyi":
					introduce = "拥有虎牙、嗜血虎爪、横扫千军才能发挥出奥义的最大威力";
					break;
				case "sld":
					introduce = "恢复一定生命值，并对周围怪物造成伤害";
					break;
				case "txlj":
					introduce = "宠物帮主人承受部分伤害，并一起恢复生命";
					break;
				case "sybh":
					introduce = "对周围怪物造成伤害";
					break;
				case "xwaoyi":
					introduce = "拥有水疗盾、同心链接、水湮八荒才能发挥出奥义的最大威力";
					break;
				case "np":
					introduce = "当生命低于20%的时候将化成朱雀丹，数秒后满血复活";
					break;
				case "bshn":
					introduce = "对前方怪物造成伤害";
					break;
				case "dhly":
					introduce = "对周围怪物造成较大的伤害";
					break;
				case "zqaoyi":
					introduce = "拥有涅磐、不死火鸟、地火燎原才能发挥出奥义的最大威力";
					break;
				case "fs":
					introduce = "分身一起攻击敌人，分身消失后，会恢复生命";
					break;
				case "sdcc":
					introduce = "释放闪电向前冲刺，对前方怪物造成伤害";
					break;
				case "ltwj":
					introduce = "召唤雷电，对周围怪物造成伤";
					break;
				case "qlaoyi":
					introduce = "拥有分身、闪电冲刺、雷霆万钧才能发挥奥义的最大威力";
					break;
				case "yg":
					introduce = "攻击时有概率落下一道月光";
					break;
				case "jf":
					introduce = "提高宠物自身普通攻击频率和闪避能力";
					break;
				case "bs":
					introduce = "飞到空中，狙击一个范围，附带冰冻";
					break;
				case "ysaoyi":
					introduce = "制造一轮明月，增加触发月光概率，并且持续回复玉兔和主人的生命值";
					break;
				case "hybt":
					introduce = "移动后沿路蔓延火焰";
					break;
				case "hhjt":
					introduce = "践踏地面周围喷射出数道火花";
					break;
				case "sc":
					introduce = "低头倾身快速冲向前方怪物，进行撕咬攻击";
					break;
				case "hxfb":
					introduce = "丢出三叉飞镖，之后飞回子鼠";
					break;
				case "zsaoyi":
					introduce = "拥有鼠窜、回旋飞镖才能发挥出奥义的最大威力";
			}
			return introduce;
		}
		
		public function findHasStudySkill(param1:String):Boolean
		{
			for each (var item:* in this.skill)
			{
				if (item.sname == param1)
				{
					return true;
				}
			}
			return false;
		}
		
		public function getPetHarmObj(skillName:String):Object
		{
			var harmData:Object = {
				"first" : 0,
				"second": 0
			};
			switch (skillName)
			{
				case "tsml":
					harmData.first = petState * 6 * warpower;
					break;
				case "zrsh":
					harmData.first = petState * 4 * technique;
					break;
				case "smzf":
					harmData.first = petState * 50 * warpower;
					break;
				case "mfby":
					harmData.first = petState * 50 * technique;
					break;
				case "qlfj":
					harmData.first = (0.05 + petState / 100) * warpower;
					break;
				case "sxkb":
					harmData.first = petState * 0.07 * technique;
					harmData.second = (30 + petState * 5) * warpower / 2;
					break;
				case "fsnl":
					harmData.first = petState * 30 * technique;
					harmData.second = (30 + petState * 5) * warpower / 2;
					break;
				case "smjc":
					harmData.first = petState * 70 * technique;
					harmData.second = (30 + petState * 5) * warpower / 2;
					break;
				case "mfjc":
					harmData.first = petState * 70 * technique;
					harmData.second = (30 + petState * 5) * warpower / 2;
					break;
				case "gjjc":
					harmData.first = petState * 10 * technique;
					harmData.second = (30 + petState * 5) * warpower / 2;
					break;
				case "fyjc":
					harmData.first = petState * 5 * technique;
					harmData.second = (30 + petState * 5) * warpower / 2;
					break;
				case "xj":
					harmData.first = 0.1 * atk;
					break;
				case "lj":
					harmData.first = atk;
					break;
				case "lyq":
					harmData.first = 6 * atk;
					break;
				case "sp":
					harmData.first = 2 * atk;
					break;
				case "bd":
					harmData.first = 2 * atk;
					break;
				case "bz":
					harmData.first = 5 * atk;
					break;
				case "pms":
					harmData.first = 2 * atk;
					break;
				case "ss":
					harmData.first = 0;
					break;
				case "kmsk":
					harmData.first = 5 * atk;
					break;
				case "hy":
					harmData.first = 2 * atk;
					break;
				case "sxhz":
					harmData.first = 4 * atk;
					break;
				case "hsqj":
					harmData.first = 6 * atk;
					break;
				case "sld":
					harmData.first = atk;
					break;
				case "txlj":
					harmData.first = 5 * technique;
					harmData.second = 4 * warpower;
					break;
				case "sybh":
					harmData.first = 6 * atk;
					break;
				case "np":
					harmData.first = 0;
					break;
				case "bshn":
					harmData.first = 2 * atk;
					break;
				case "dhly":
					harmData.first = 10 * atk;
					break;
				case "fs":
					harmData.first = 0;
					break;
				case "sdcc":
					harmData.first = atk;
					break;
				case "ltwj":
					harmData.first = 6 * atk;
					break;
				case "yg":
					harmData.first = 2 * atk;
					break;
				case "jf":
					harmData.first = 0;
					break;
				case "bs":
					harmData.first = 8 * atk;
					break;
				case "hybt":
					harmData.first = atk;
					break;
				case "hhjt":
					harmData.first = 6 * atk;
					break;
				case "sc":
					harmData.first = 1.3 * atk;
					break;
				case "hxfb":
					harmData.first = 5 * atk;
					break;
				case "ysaoyi":
				case "jgaoyi":
				case "tmaoyi":
				case "bhaoyi":
				case "zqaoyi":
				case "xwaoyi":
				case "qlaoyi":
				case "zsaoyi":
					harmData.first = 0;
			}
			return harmData;
		}
		
		/**
		 * 获取下一级的经验
		 * @return 下一级的经验
		 */
		public function getPetNextLevelExp():int
		{
			var exp:int;
			if (level <= 10)
			{
				exp = level * 50;
			}
			else
			{
				exp = (level + 1) * (level + 1) * (5 + (level - 10) * 2);
			}
			return exp;
		}
		
		/**
		 * 查找宠物技能蓝耗
		 * @param skillName 技能名称
		 * @return
		 */
		public function findPetUsedMagic(skillName:String):uint
		{
			switch (skillName)
			{
				case "tsml":
				case "zrsh":
				case "smzf":
				case "mfby":
				case "qlfj":
					return 0;
				case "sxkb":
				case "fsnl":
				case "smjc":
				case "mfjc":
				case "gjjc":
				case "fyjc":
					return 100;
				case "xj":
					return 50;
				case "lj":
					return 70;
				case "lyq":
					return 90;
				case "sp":
					return 60;
				case "bd":
					return 90;
				case "bz":
					return 120;
				case "pms":
					return 50;
				case "ss":
					return 70;
				case "kmsk":
					return 90;
				case "hy":
					return 50;
				case "sxhz":
					return 70;
				case "hsqj":
					return 90;
				case "sld":
					return 50;
				case "txlj":
					return 70;
				case "sybh":
					return 90;
				case "np":
					return 100;
				case "bshn":
					return 70;
				case "dhly":
					return 90;
				case "fs":
					return 50;
				case "sdcc":
					return 70;
				case "ltwj":
					return 90;
				case "yg":
					return 0;
				case "jf":
					return 70;
				case "bs":
					return 90;
				case "hybt":
					return 50;
				case "hhjt":
					return 70;
				case "sc":
					return 50;
				case "hxfb":
					return 80;
				case "jgaoyi":
				case "tmaoyi":
				case "bhaoyi":
				case "xwaoyi":
				case "zqaoyi":
				case "qlaoyi":
				case "ysaoyi":
				case "zsaoyi":
					return 100;
				default:
					return 0;
			}
		}
		
		/**
		 * 转换宠物技能名称
		 * @param skillName 技能名称
		 * @return
		 */
		public function transPetChinaSkillName(skillName:String):String
		{
			switch (skillName)
			{
				case "tsml":
					return "天生蛮力";
				case "zrsh":
					return "自然守护";
				case "smzf":
					return "生命祝福";
				case "mfby":
					return "魔法庇佑";
				case "qlfj":
					return "强力反击";
				case "sxkb":
					return "嗜血狂暴";
				case "fsnl":
					return "法术能量";
				case "smjc":
					return "生命加成";
				case "mfjc":
					return "魔法加成";
				case "gjjc":
					return "攻击加成";
				case "fyjc":
					return "防御加成";
				case "xj":
					return "献祭";
				case "lj":
					return "连击";
				case "lyq":
					return "烈焰拳";
				case "jgaoyi":
					return "金刚奥义";
				case "sp":
					return "水泡";
				case "bd":
					return "冰冻";
				case "bz":
					return "冰锥";
				case "tmaoyi":
					return "天马奥义";
				case "pms":
					return "魔破杀";
				case "ss":
					return "瞬闪";
				case "kmsk":
					return "狂魔闪空";
				case "hy":
					return "虎牙";
				case "sxhz":
					return "嗜血虎爪";
				case "hsqj":
					return "横扫千军";
				case "bhaoyi":
					return "白虎奥义";
				case "sld":
					return "水疗盾";
				case "txlj":
					return "同心链接";
				case "sybh":
					return "水湮八荒";
				case "xwaoyi":
					return "玄武奥义";
				case "np":
					return "涅磐";
				case "bshn":
					return "不死火鸟";
				case "dhly":
					return "地火燎原";
				case "zqaoyi":
					return "朱雀奥义";
				case "fs":
					return "分身";
				case "sdcc":
					return "闪电冲刺";
				case "ltwj":
					return "雷霆万钧";
				case "qlaoyi":
					return "青龙奥义";
				case "yg":
					return "月光";
				case "jf":
					return "疾风";
				case "bs":
					return "冰陨";
				case "ysaoyi":
					return "月神奥义";
				case "hybt":
					return "火焰奔腾";
				case "hhjt":
					return "火花践踏";
				case "sc":
					return "鼠蹿";
				case "hxfb":
					return "回旋飞镖";
				case "zsaoyi":
					return "究极奥义";
				default:
					return "";
			}
		}
		
		public function changePetSkillIntroduce():void
		{
			for each (var item:Object in this.skill)
			{
				item.sinfo = this.getIntroByName(item.sname);
			}
		}
		
		/**
		 * 宠物还童
		 */
		public function makePetBecomeChild():void
		{
			level = 1;
			curExp = 0;
			quality = 1;
			lifetime = 100;
			petName = petId + "1";
			this.transPetChinaName();
			this.initPetInfoData();
		}
		
		public function setDoWhenLevelUp(func:Function):void
		{
			this.doWhenLevelUp = func;
		}
		
		public function setDoWhenChangeState(func:Function):void
		{
			this.doWhenChangeState = func;
		}
		
		private function initPetInfoData():void
		{
			var dataObj:Object = {
				hpR        : [0, 0],
				mpR        : [0, 0],
				atkR       : [0, 0],
				defR       : [0, 0],
				hpQualityR : [0, 0],
				mpQualityR : [0, 0],
				atkQualityR: [0, 0],
				defQualityR: [0, 0]
			}
			switch (petId)
			{
				case "monkey":
					if (this.quality == 1)
					{
						with (dataObj)
						{
							hpQualityR = 1040;
							mpQualityR = 1040;
							atkQualityR = 1040;
							defQualityR = 1040;
							hpR = 200;
							mpR = 150;
							atkR = 20;
							defR = 6;
						}
					}
					else
					{
						with (dataObj)
						{
							hpQualityR = 800;
							mpQualityR = 800;
							atkQualityR = 800;
							defQualityR = 800;
							hpR = [150, 200];
							mpR = [100, 150];
							atkR = [10, 20];
							defR = [2, 6];
						}
					}
					break;
				case "horse":
					if (this.quality == 1)
					{
						with (dataObj)
						{
							hpQualityR = 949;
							mpQualityR = 1222;
							atkQualityR = 1105;
							defQualityR = 600;
							hpR = 150;
							mpR = 200;
							atkR = 25;
							defR = 6;
						}
					}
					else
					{
						with (dataObj)
						{
							hpQualityR = [530, 730];
							mpQualityR = [640, 840];
							atkQualityR = [650, 850];
							defQualityR = [200, 400];
							hpR = [100, 150];
							mpR = [100, 150];
							atkR = [10, 20];
							defR = [2, 6];
						}
					}
					break;
				case "ufo":
					if (this.quality == 1)
					{
						with (dataObj)
						{
							hpQualityR = 1170;
							mpQualityR = 1040;
							atkQualityR = 1170;
							defQualityR = 351;
							hpR = 250;
							mpR = 150;
							atkR = 30;
							defR = 8;
						}
					}
					else
					{
						with (dataObj)
						{
							hpQualityR = [700, 900];
							mpQualityR = [500, 800];
							atkQualityR = [700, 900];
							defQualityR = [200, 270];
							hpR = [200, 250];
							mpR = [100, 150];
							atkR = [15, 30];
							defR = [2, 8];
						}
					}
					break;
				case "tigress":
					if (this.quality == 1)
					{
						with (dataObj)
						{
							hpQualityR = 1300;
							mpQualityR = 1040;
							atkQualityR = 1300;
							defQualityR = 520;
							hpR = 500;
							mpR = 150;
							atkR = 30;
							defR = 8;
						}
					}
					else
					{
						with (dataObj)
						{
							hpQualityR = [800, 1000];
							mpQualityR = [500, 800];
							atkQualityR = [800, 1000];
							defQualityR = [300, 400];
							hpR = [200, 500];
							mpR = [100, 150];
							atkR = [15, 30];
							defR = [2, 8];
						}
					}
					break;
				case "turtle":
					if (this.quality == 1)
					{
						with (dataObj)
						{
							hpQualityR = 1560;
							mpQualityR = 910;
							atkQualityR = 1170;
							defQualityR = 611;
							hpR = 600;
							mpR = 150;
							atkR = 25;
							defR = 10;
						}
					}
					else
					{
						with (dataObj)
						{
							hpQualityR = [1000, 1500];
							mpQualityR = [500, 700];
							atkQualityR = [800, 900];
							defQualityR = [300, 600];
							hpR = [300, 600];
							mpR = [100, 150];
							atkR = [10, 25];
							defR = [5, 10];
						}
					}
					break;
				case "phoenix":
					if (this.quality == 1)
					{
						with (dataObj)
						{
							hpQualityR = 1170;
							mpQualityR = 1170;
							atkQualityR = 1300;
							defQualityR = 470;
							hpR = 600;
							mpR = 150;
							atkR = 25;
							defR = 10;
						}
					}
					else
					{
						with (dataObj)
						{
							hpQualityR = [600, 900];
							mpQualityR = [600, 900];
							atkQualityR = [800, 1000];
							defQualityR = [200, 400];
							hpR = [200, 450];
							mpR = [120, 200];
							atkR = [16, 32];
							defR = [2, 6];
						}
					}
					break;
				case "dragon":
					if (this.quality == 1)
					{
						with (dataObj)
						{
							hpQualityR = 1430;
							mpQualityR = 780;
							atkQualityR = 1430;
							defQualityR = 520;
							hpR = 400;
							mpR = 200;
							atkR = 30;
							defR = 8;
						}
					}
					else
					{
						with (dataObj)
						{
							hpQualityR = [900, 1100];
							mpQualityR = [500, 600];
							atkQualityR = [800, 1100];
							defQualityR = [300, 400];
							hpR = [200, 400];
							mpR = [150, 200];
							atkR = [15, 30];
							defR = [2, 8];
						}
					}
					break;
				case "rabbit":
					if (this.quality == 1)
					{
						with (dataObj)
						{
							hpQualityR = 1100;
							mpQualityR = 1100;
							atkQualityR = 1000;
							defQualityR = 500;
							hpR = 500;
							mpR = 200;
							atkR = 30;
							defR = 5;
						}
					}
					else
					{
						with (dataObj)
						{
							hpQualityR = [750, 1100];
							mpQualityR = [750, 1100];
							atkQualityR = [800, 1000];
							defQualityR = [300, 500];
							hpR = [200, 500];
							mpR = [120, 200];
							atkR = [15, 30];
							defR = [2, 5];
						}
					}
					break;
				case "roomhorse":
					if (this.quality == 1)
					{
						with (dataObj)
						{
							hpQualityR = 1350;
							mpQualityR = 1100;
							atkQualityR = 1200;
							defQualityR = 450;
							hpR = 700;
							mpR = 800;
							atkR = 50;
							defR = 10;
						}
					}
					else
					{
						with (dataObj)
						{
							hpQualityR = [700, 1300];
							mpQualityR = [550, 900];
							atkQualityR = [900, 1250];
							defQualityR = [200, 400];
							hpR = [500, 700];
							mpR = [600, 800];
							atkR = [25, 50];
							defR = [5, 10];
						}
					}
					break;
				case "mouse":
					if (this.quality == 1)
					{
						with (dataObj)
						{
							hpQualityR = 1350;
							mpQualityR = 400;
							atkQualityR = 1200;
							defQualityR = 450;
							hpR = 700;
							mpR = 800;
							atkR = 50;
							defR = 20;
						}
					}
					else
					{
						with (dataObj)
						{
							hpQualityR = [700, 1300];
							mpQualityR = [200, 400];
							atkQualityR = [900, 1200];
							defQualityR = [200, 400];
							hpR = [500, 700];
							mpR = [600, 800];
							atkR = [25, 50];
							defR = [15, 20];
						}
					}
					break;
			}
			//以下是对数据的处理，不用管，加入宠物只需要拓展上面的部分
			if (dataObj.hpR is Array)
			{
				hpMax = RandomUtil.randInt(dataObj.hpR[0], dataObj.hpR[1]);
			}
			else
			{
				hpMax = int(dataObj.hpR);
			}
			if (dataObj.mpR is Array)
			{
				mpMax = RandomUtil.randInt(dataObj.mpR[0], dataObj.mpR[1]);
			}
			else
			{
				mpMax = int(dataObj.mpR);
			}
			if (dataObj.atkR is Array)
			{
				atk = RandomUtil.randInt(dataObj.atkR[0], dataObj.atkR[1]);
			}
			else
			{
				atk = int(dataObj.atkR);
			}
			if (dataObj.defR is Array)
			{
				def = RandomUtil.randInt(dataObj.defR[0], dataObj.defR[1]);
			}
			else
			{
				def = int(dataObj.defR);
			}
			if (dataObj.hpQualityR is Array)
			{
				hpQuality = RandomUtil.randInt(dataObj.hpQualityR[0], dataObj.hpQualityR[1]);
			}
			else
			{
				hpQuality = int(dataObj.hpQualityR);
			}
			if (dataObj.mpQualityR is Array)
			{
				mpQuality = RandomUtil.randInt(dataObj.mpQualityR[0], dataObj.mpQualityR[1]);
			}
			else
			{
				mpQuality = int(dataObj.mpQualityR);
			}
			if (dataObj.atkQualityR is Array)
			{
				atkQuality = RandomUtil.randInt(dataObj.atkQualityR[0], dataObj.atkQualityR[1]);
			}
			else
			{
				atkQuality = int(dataObj.atkQualityR);
			}
			if (dataObj.defQualityR is Array)
			{
				defQuality = RandomUtil.randInt(dataObj.defQualityR[0], dataObj.defQualityR[1]);
			}
			else
			{
				defQuality = int(dataObj.defQualityR);
			}
			if (level > 1)
			{
				hp += hpQuality * level * 0.08;
				mp += mpQuality * level * 0.08;
				atk += atkQuality * level * 0.015;
				def += defQuality * level * 0.01;
			}
			if (this.quality == 1)
			{
				perception = RandomUtil.randInt(4, 7);
				technique = RandomUtil.randInt(4, 8);
				warpower = RandomUtil.randInt(4, 8);
			}
			else
			{
				perception = RandomUtil.randInt(1, 6);
				technique = RandomUtil.randInt(1, 6);
				warpower = RandomUtil.randInt(1, 6);
			}
			resetPetState();
		}
		
		/**
		 * 瞬间学习技能（用于重置技能、升级时获取技能）,会根据level进行取舍，因此level的传入比较关键
		 * level条件：3*level-1
		 * @param level 等级
		 */
		private function studySkillSuddenly(level:uint):void
		{
			if (skill.length >= perception)
			{
				return;
			}
			var i:int = 0;
			while (i < MaxAttribConst.MaxPetLevel)
			{
				if (level == 3 * (i + 1) - 1)
				{
					//循环到对应倍数后执行学习技能
					break;
				}
				if (i == 59)
				{
					//只有60级之前才能学习技能
					return;
				}
				i++;
			}
			if (RandomUtil.randBoolean(60))
			{
				return;
			}
			var targetSkill:String = RandomUtil.randSwitch(allSkill);
			var idx:int = allSkill.indexOf(targetSkill);
			if (idx != -1)
			{
				var skillData:Object = {
					"sname": targetSkill,
					"sinfo": this.getIntroByName(targetSkill)
				};
				skill.push(skillData);
				allSkill.splice(idx, 1);
			}
		}
		
		private function addSpecialSkill():void
		{
			var _loc1_:String = "";
			var _loc2_:String = "";
			switch (this.petName)
			{
				case "monkey1":
					_loc1_ = "xj";
					break;
				case "monkey2":
					_loc2_ = "xj";
					_loc1_ = "lj";
					break;
				case "monkey3":
					_loc2_ = "lj";
					_loc1_ = "lyq";
					break;
				case "horse1":
					_loc1_ = "sp";
					break;
				case "horse2":
					_loc2_ = "sp";
					_loc1_ = "bd";
					break;
				case "horse3":
					_loc2_ = "bd";
					_loc1_ = "bz";
					break;
				case "ufo1":
					_loc1_ = "pms";
					break;
				case "ufo2":
					_loc2_ = "pms";
					_loc1_ = "ss";
					break;
				case "ufo3":
					_loc2_ = "ss";
					_loc1_ = "kmsk";
					break;
				case "tigress1":
					_loc1_ = "hy";
					break;
				case "tigress2":
					_loc2_ = "hy";
					_loc1_ = "sxhz";
					break;
				case "tigress3":
					_loc2_ = "sxhz";
					_loc1_ = "hsqj";
					break;
				case "turtle1":
					_loc1_ = "sld";
					break;
				case "turtle2":
					_loc2_ = "sld";
					_loc1_ = "txlj";
					break;
				case "turtle3":
					_loc2_ = "txlj";
					_loc1_ = "sybh";
					break;
				case "phoenix1":
					_loc1_ = "np";
					break;
				case "phoenix2":
					_loc2_ = "np";
					_loc1_ = "bshn";
					break;
				case "phoenix3":
					_loc2_ = "bshn";
					_loc1_ = "dhly";
					break;
				case "dragon1":
					_loc1_ = "fs";
					break;
				case "dragon2":
					_loc2_ = "fs";
					_loc1_ = "sdcc";
					break;
				case "dragon3":
					_loc2_ = "sdcc";
					_loc1_ = "ltwj";
					break;
				case "rabbit1":
					_loc1_ = "yg";
					break;
				case "rabbit2":
					_loc2_ = "yg";
					_loc1_ = "jf";
					break;
				case "rabbit3":
					_loc2_ = "jf";
					_loc1_ = "bs";
					break;
				case "roomhorse1":
					_loc1_ = "hybt";
					break;
				case "roomhorse2":
					_loc1_ = "hybt";
					break;
				case "roomhorse3":
					_loc1_ = "hybt";
					break;
				case "roomhorse4":
					_loc2_ = "hybt";
					_loc1_ = "hhjt";
					break;
				case "mouse1":
					_loc1_ = "sc";
					break;
				case "mouse2":
					_loc1_ = "sc";
					break;
				case "mouse3":
					_loc1_ = "sc";
					break;
				case "mouse4":
					_loc2_ = "sc";
					_loc1_ = "hxfb";
			}
			if (_loc2_ != "")
			{
				this.removeSomeSkillFromAllSkill(_loc2_);
			}
			if (_loc1_ != "")
			{
				if (!this.findHasStudySkill(_loc1_))
				{
					if (!this.findHasInAllSkill(_loc1_))
					{
						this.allSkill.push(_loc1_);
					}
				}
			}
		}
		
		private function reSetPetAttributeValue():void
		{
			hpMax += hpQuality * 0.12;
			mpMax += mpQuality * 0.08;
			atk += atkQuality * 0.015;
			def += defQuality * 0.01;
			if (level >= 60)
			{
				miss += RandomUtil.randInt(0, 2);
				magicDef += RandomUtil.randInt(0, 2);
				crit += RandomUtil.randInt(0, 2);
			}
			resetPetState();
		}
		
		private function removeSomeSkillFromAllSkill(param1:String):void
		{
			var idx:int = this.allSkill.indexOf(param1);
			if (idx != -1)
			{
				this.allSkill.splice(idx, 1);
			}
		}
		
		private function rePetSkill():void
		{
			switch (petId)
			{
				case "monkey":
					switch (petState)
					{
						case 1:
							this.allSkill.push("xj");
							break;
						case 2:
							this.allSkill.push("xj", "lj");
							break;
						case 3:
							this.allSkill.push("xj", "lj", "lyq");
							break;
						case 4:
							this.allSkill.push("xj", "lj", "lyq", "jgaoyi");
							break;
					}
					break;
				case "horse":
					switch (petState)
					{
						case 1:
							this.allSkill.push("sp");
							break;
						case 2:
							this.allSkill.push("sp", "bd");
							break;
						case 3:
							this.allSkill.push("sp", "bd", "bz");
							break;
						case 4:
							this.allSkill.push("sp", "bd", "bz", "tmaoyi");
							break;
					}
					break;
				case "ufo":
					switch (petState)
					{
						case 1:
							this.allSkill.push("pms");
							break;
						case 2:
							this.allSkill.push("pms", "ss");
							break;
						case 3:
							this.allSkill.push("pms", "ss", "kmsk");
							break;
						case 4:
							this.allSkill.push("pms", "ss", "kmsk");
							break;
					}
					break;
				case "tigress":
					switch (petState)
					{
						case 1:
							this.allSkill.push("hy");
							break;
						case 2:
							this.allSkill.push("hy", "sxhz");
							break;
						case 3:
							this.allSkill.push("hy", "sxhz", "hsqj");
							break;
						case 4:
							this.allSkill.push("hy", "sxhz", "hsqj", "bhaoyi");
							break;
					}
					break;
				case "turtle":
					switch (petState)
					{
						case 1:
							this.allSkill.push("sld");
							break;
						case 2:
							this.allSkill.push("sld", "txlj");
							break;
						case 3:
							this.allSkill.push("sld", "txlj", "sybh");
							break;
						case 4:
							this.allSkill.push("sld", "txlj", "sybh", "xwaoyi");
							break;
					}
					break;
				case "phoenix":
					switch (petState)
					{
						case 1:
							this.allSkill.push("np");
							break;
						case 2:
							this.allSkill.push("np", "bshn");
							break;
						case 3:
							this.allSkill.push("np", "bshn", "dhly");
							break;
						case 4:
							this.allSkill.push("np", "bshn", "dhly", "zqaoyi");
							break;
					}
					break;
				case "dragon":
					switch (petState)
					{
						case 1:
							this.allSkill.push("fs");
							break;
						case 2:
							this.allSkill.push("fs", "sdcc");
							break;
						case 3:
							this.allSkill.push("fs", "sdcc", "ltwj");
							break;
						case 4:
							this.allSkill.push("fs", "sdcc", "ltwj", "qlaoyi");
							break;
					}
					break;
				case "rabbit":
					switch (petState)
					{
						case 1:
							this.allSkill.push("yg");
							break;
						case 2:
							this.allSkill.push("yg", "jf");
							break;
						case 3:
							this.allSkill.push("yg", "jf", "bs");
							break;
						case 4:
							this.allSkill.push("yg", "jf", "bs", "ysaoyi");
							break;
					}
					break;
				case "roomhorse":
					switch (petState)
					{
						case 1:
							this.allSkill.push("hybt");
							break;
						case 2:
							this.allSkill.push("hybt");
							break;
						case 3:
							this.allSkill.push("hybt");
							break;
						case 4:
							this.allSkill.push("hybt", "hhjt");
							break;
					}
					break;
				case "mouse":
					switch (petState)
					{
						case 1:
							this.allSkill.push("sc");
							break;
						case 2:
							this.allSkill.push("sc");
							break;
						case 3:
							this.allSkill.push("sc", "hxfb");
							break;
						case 4:
							this.allSkill.push("sc", "hxfb", "zsaoyi");
							break;
					}
					break;
			}
			for (var i:int = 2; i <= level; i++)
			{
				studySkillSuddenly(i);
			}
			this.addPassiveAfterUpdata();
		}
		
		private function findHasInAllSkill(param1:String):Boolean
		{
			for each (var data:Object in this.allSkill)
			{
				if (param1 == data)
				{
					return true;
				}
			}
			return false;
		}
		
		private function hasStudyPassiveSkill(sklName:String):void
		{
			var sklObj:Object = this.getPetHarmObj(sklName);
			switch (sklName)
			{
				case "tsml":
					atk += sklObj.first;
					break;
				case "zrsh":
					def += sklObj.first;
					break;
				case "smzf":
					hpMax += sklObj.first;
					setFullHp();
					break;
				case "mfby":
					mpMax += sklObj.first;
					setFullMp();
					break;
			}
		}
		
		private function deletePassiveWhenUpdata():void
		{
			var harmData:Object = {
				"first" : 0,
				"second": 0
			};
			for each (var data:Object in this.skill)
			{
				harmData = getPetHarmObj(data.sname);
				switch (data.sname)
				{
					case "tsml":
						atk -= Number(harmData.first);
						break;
					case "zrsh":
						def -= Number(harmData.first);
						break;
					case "smzf":
						hpMax -= Number(harmData.first);
						setFullHp();
						break;
					case "mfby":
						mpMax -= Number(harmData.first);
						setFullMp();
				}
			}
		}
		
		private function transPetChinaName():void
		{
			switch (this.petName)
			{
				case "monkey1":
					this.petChinaName = "火丸";
					break;
				case "monkey2":
					this.petChinaName = "灵猴";
					break;
				case "monkey3":
					this.petChinaName = "火猿";
					break;
				case "monkey4":
					this.petChinaName = "烈焰金刚";
					break;
				case "horse1":
					this.petChinaName = "雪球";
					break;
				case "horse2":
					this.petChinaName = "雪马";
					break;
				case "horse3":
					this.petChinaName = "寒野";
					break;
				case "horse4":
					this.petChinaName = "极寒天马";
					break;
				case "ufo1":
					this.petChinaName = "小飞";
					break;
				case "ufo2":
					this.petChinaName = "裂云";
					break;
				case "ufo3":
					this.petChinaName = "冲霄";
					break;
				case "tigress1":
					this.petChinaName = "虎丸";
					break;
				case "tigress2":
					this.petChinaName = "白灵虎";
					break;
				case "tigress3":
					this.petChinaName = "白虎将军";
					break;
				case "tigress4":
					this.petChinaName = "白虎战神";
					break;
				case "turtle1":
					this.petChinaName = "龟布";
					break;
				case "turtle2":
					this.petChinaName = "墨玄龟";
					break;
				case "turtle3":
					this.petChinaName = "玄武将军";
					break;
				case "turtle4":
					this.petChinaName = "玄武大帝";
					break;
				case "phoenix1":
					this.petChinaName = "雀蛋";
					break;
				case "phoenix2":
					this.petChinaName = "炎皇雀";
					break;
				case "phoenix3":
					this.petChinaName = "朱雀将军";
					break;
				case "phoenix4":
					this.petChinaName = "朱雀女皇";
					break;
				case "dragon1":
					this.petChinaName = "龙仔";
					break;
				case "dragon2":
					this.petChinaName = "绿英龙";
					break;
				case "dragon3":
					this.petChinaName = "青龙将军";
					break;
				case "dragon4":
					this.petChinaName = "青龙妖圣";
					break;
				case "rabbit1":
					this.petChinaName = "月兔";
					break;
				case "rabbit2":
					this.petChinaName = "疾风兔";
					break;
				case "rabbit3":
					this.petChinaName = "寒冰玉兔";
					break;
				case "rabbit4":
					this.petChinaName = "冰霜月神";
					break;
				case "roomhorse1":
					this.petChinaName = "炎马";
					break;
				case "roomhorse2":
					this.petChinaName = "炎马";
					break;
				case "roomhorse3":
					this.petChinaName = "炎马";
					break;
				case "roomhorse4":
					this.petChinaName = "烈迦";
					break;
				case "mouse1":
					this.petChinaName = "子鼠元帅";
					break;
				case "mouse2":
					this.petChinaName = "子鼠元帅";
					break;
				case "mouse3":
					this.petChinaName = "子鼠元帅";
					break;
				case "mouse4":
					this.petChinaName = "子鼠大元帅";
			}
		}
		
		public function set lifetime(value:int):void
		{
			_lifetime = value;
			if (_lifetime < 0)
			{
				_lifetime = 0;
			}
			if (_lifetime > 100)
			{
				_lifetime = 100;
			}
		}
		
		private function addPassiveAfterUpdata():void
		{
			for each(var data:Object in this.skill)
			{
				hasStudyPassiveSkill(data.sname);
			}
		}
	}
}
